<template>
    <el-form :model="userForm" status-icon :rules="rules" ref="userForm"
             label-width="150px"
             style="margin-top: 10px;color: #1f2d3d">
        <el-form-item class="form-label" label="用户名" prop="userName">
            <el-col :span="19">
                <el-input v-model="userForm.userName" placeholder="用户名"
                          maxlength="11" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="密码" prop="pwd">
            <el-col :span="19">
                <el-input v-model="userForm.pwd" placeholder="密码"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="备注" prop="remark">
            <el-col :span="19">
                <el-input v-model="userForm.remark" placeholder="备注"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
    </el-form>
</template>

<script>
    import qs from 'qs';

    export default {
        name: "NewNode",
        data() {
            return {
                userForm: {
                    id: '',
                    userName: '',
                    pwd: '',
                    rid: '',
                    level: '',
                    isdel: '',
                    remark: ''
                },
                rules: {
                    userName: [],
                    pwd: [],
                    rid: [],
                    level: [],
                    isdel: [],
                    remark: []
                }
            }
        },
        props: {
            id: {
                type: Number,
                default: -1
            }
        },
        mounted() {
            if (this.id !== -1) {
                axios.post("/bjdzms/user/findById",
                    qs.stringify({
                        'id': this.id
                    })).then(res => {
                    this.userForm = res.data;
                });
            }
        },
        methods: {
            to(path) {
                this.$router.push({name: path});
            }
            ,
            submitForm() {
                if (this.id !== -1) {
                    this.userForm.id = this.id;
                    axios.post("/bjdzms/user/upd",
                        qs.stringify(this.userForm)
                    ).then(res => {
                        this.$emit('updateData');
                    });
                } else {
                    axios.post("/bjdzms/user/add",
                        qs.stringify(this.userForm)
                    ).then(res => {
                        this.$emit('updateData1');
                    });
                }
            }
        }
    }
</script>

<style>
    .el-upload-dragger {
        height: 40px !important;
    }
</style>

<style scoped>
    .el-header {
        background: #EBEBEB;
        color: #e5e9ef;
        font-size: 2em;
        line-height: 80px;
        border: 5px solid #EBEBEB;
    }

    .el-main {
        background: #fff;
    }

    .el-container {
        height: 100%;
    }

    .el-form-item {
        width: 610px;
    }
</style>
